<?php

declare(strict_types=1);

namespace App\Entities;

class CleanerEntity extends ABaseEntity
{
    public function __construct(CleanerModel $model)
    {
        $this->model = $model;
    }

    /**
     * @return CleanerEntity
     */
    public static function findByPhone(string $phone)
    {
        $model = CleanerModel::where('phone', $phone)->first();
        if ($model === null) {
            return $model;
        }

        return new self($model);
    }

    public function getId(): int
    {
        return $this->model->id;
    }

    //avatar
    public function getAvatar(): string
    {
        return $this->model->avatar;
    }

    public function setAvatar(string $avatar): void
    {
        $this->model->avatar = $avatar;
    }

    public function getRealName(): string
    {
        return (string) $this->model->realname;
    }

    /**
     * 返回处理过后的保洁员名字
     */
    public function getSafeRealName(): string
    {
        return mb_substr($this->getRealName(), 0, 1) .
            ($this->getGender() == CleanerModel::GENDER_MALE ? '先生' : '女士');
    }

    public function setRealName(string $realName): void
    {
        $this->model->realname = $realName;
    }

    public function getPhone(): string
    {
        return $this->model->phone;
    }

    public function getSafePhone(): string
    {
        return substr_replace($this->getPhone(), '****', 3, 4);
    }

    public function setPhone(string $phone): void
    {
        $this->model->phone = $phone;
    }

    //gender
    public function getGender(): int
    {
        return $this->model->gender;
    }

    public function setGender(int $gender): void
    {
        $this->model->gender = $gender;
    }

    //city_id
    public function getCityId(): int
    {
        return $this->model->city_id;
    }

    public function setCityId(int $cityId): void
    {
        $this->model->city_id = $cityId;
    }

    //status
    public function getStatus(): int
    {
        return $this->model->status;
    }

    public function setStatus(int $status): void
    {
        $this->model->status = $status;
    }

    public function getPassword(): string
    {
        return $this->model->password;
    }

    public function setPassword(string $password): void
    {
        $this->model->password = $password;
    }
}
